@extends('Layouts.iframe')
@section('content')
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 字典管理 <span class="c-gray en">&gt;</span> 字典列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
    <div class="page-container">
        <div class="text-l">
            <form action="{{route('dictionary.index')}}" method="get">
                字典搜索 ：
                <input type="text" name="keyword" id="" value="{{$dictionaries->keyword}}" placeholder="可输入 配置项/描述/值 进行搜索" style="width:250px" class="input-text">
                <button name="" id="" class="btn btn-success" type="submit"><i class="Hui-iconfont">&#xe665;</i> </button>
            </form>
        </div>
        @can('dictionary.create')
        <div class="cl pd-5 bg-1 bk-gray mt-20">
            <span class="l">
                <a class="btn btn-primary radius" onclick="dictionary_add('添加字典','{{route('dictionary.create')}}','','700')" href="javascript:;">
                    <i class="Hui-iconfont">&#xe600;</i>新增字典
                </a>
            </span>
        </div>
        @endcan
        <div class="mt-20">
            <table class="table table-border table-bordered table-hover table-bg table-sort">
                <thead>
                <tr class="text-c">
                    <th width="20">ID</th>
                    <th width="40">配置项</th>
                    <th width="80">描述(规则)</th>
                    <th width="100">值</th>
                    <th width="20">操作</th>
                </tr>
                </thead>
                <tbody>
                    @if($dictionaries->count())
                        @foreach($dictionaries as $dictionary)
                            <tr class="text-c">
                                <td>{{$dictionary->id}}</td>
                                <td>{{$dictionary->name}}</td>
                                <td>{{$dictionary->intro}}</td>
                                <td>
                                    @if($dictionary->child->count())
                                        @foreach($dictionary->child as $child)
                                            <p>
                                                <label for="">{{$child->name}}</label>
                                                @if($child->child->count())
                                                    <span> : </span><span>{{implode(',',$child->child->pluck('name')->all())}}</span>
                                                @endif
                                            </p>
                                        @endforeach
                                    @endif
                                </td>
                                <td>
                                    @can('dictionary.edit')
                                        <a href="#" onclick="dictionary_add('修改字典','{{route('dictionary.edit',['id'=>$dictionary->id])}}','','700')" class="label label-success radius">配置</a>
                                    @endcan
                                </td>
                            </tr>
                        @endforeach
                    @endif
                </tbody>
            </table>
        </div>
        <div id="pull_right">
            <div class="pull-right">
                {!! $dictionaries->render() !!}
            </div>
        </div>
    </div>
@endsection
@section('js')
    <script>
        /*字典-添加/编辑*/
        function dictionary_add(title,url,w,h){
            layer_show(title,url,w,h);
        }
        /*字典删除*/
        function dictionary_del(obj, id) {
            layer.confirm('确认要删除吗？', function (index) {
                $.ajax({
                    type: 'POST',
                    url: "{{url('admin/dictionary')}}/"+id,
                    data:{'_method':'DELETE','_token':"{{csrf_token()}}"},
                    dataType: 'json',
                    success: function (data) {
                        if(data.status===200){
                            $(obj).parents("li").remove();
                            layer.msg('删除成功!', {icon: 1, time: 2000});
                        }else {
                            layer.msg(data.msg, {icon: 1, time: 2000});
                        }
                    },
                    error: function (data) {
                        layer.msg(data.msg, {icon: 1, time: 2000});
                        console.log(data.msg);
                    },
                });
            });
        }
    </script>
@endsection